package com.ruoyi.web.controller.kubernetes;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.KubernetesGroup;
import com.ruoyi.web.service.IKubernetesGroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * K8s用户组Controller
 *
 * @author ruoyi
 * @date 2022-04-17
 */
@RestController
@RequestMapping("/kubernetes/group")
public class KubernetesGroupController extends BaseController
{
    @Autowired
    private IKubernetesGroupService kubernetesGroupService;

    /**
     * 查询K8s用户组列表
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(KubernetesGroup kubernetesGroup)
    {
        startPage();
        List<KubernetesGroup> list = kubernetesGroupService.selectKubernetesGroupList(kubernetesGroup);
        return getDataTable(list);
    }

    /**
     * 导出K8s用户组列表
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group:export')")
    @Log(title = "K8s用户组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KubernetesGroup kubernetesGroup)
    {
        List<KubernetesGroup> list = kubernetesGroupService.selectKubernetesGroupList(kubernetesGroup);
        ExcelUtil<KubernetesGroup> util = new ExcelUtil<KubernetesGroup>(KubernetesGroup.class);
        util.exportExcel(response, list, "K8s用户组数据");
    }

    /**
     * 获取K8s用户组详细信息
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(kubernetesGroupService.selectKubernetesGroupById(id));
    }

    /**
     * 新增K8s用户组
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group:add')")
    @Log(title = "K8s用户组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KubernetesGroup kubernetesGroup)
    {
        return toAjax(kubernetesGroupService.insertKubernetesGroup(kubernetesGroup));
    }

    /**
     * 修改K8s用户组
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group:edit')")
    @Log(title = "K8s用户组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KubernetesGroup kubernetesGroup)
    {
        return toAjax(kubernetesGroupService.updateKubernetesGroup(kubernetesGroup));
    }

    /**
     * 删除K8s用户组
     */
    @PreAuthorize("@ss.hasPermi('kubernetes:group:remove')")
    @Log(title = "K8s用户组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(kubernetesGroupService.deleteKubernetesGroupByIds(ids));
    }
}
